#!/usr/bin/env python
#
#       Players.py
#       
#       Copyright 2009 Ben Davis <its.hip@gmail.com>
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

from Client import Client
client = Client()

class Players(dict):
    def __setitem__(self, i, y):
        y.__setup__((y.number - client.game.player.number) % (len(self) + 1))
        dict.__setitem__(self, i, y)
        
    def __setup__(self):
        for player in self.values():
            player.__setup__((player.number - client.game.player.number) % len(self))
    
    def get_key(self, item):
        for key, element in self.items():
            if element == item:
                return key
        raise KeyError

class Player(object):
    def __setup__(self, player):
        self.ships.__setup__(player)
        
    def key(self):
        return self.__key__
